<?php

class DefinedAction extends CommonAction {

    // 查询数据
    public function index() {
        $this->display();
    }
	public function indexjson() {
        $Defined = M("Defined");
		$list = $Defined->order('id desc')->select();
		$i = 0;
		foreach($list AS $row ){
			$defined[$i]['table_id'] = $row['id'];
			$defined[$i]['table_name'] = $row['name'];
			$defined[$i]['table_value'] = $row['value'];
			$defined[$i]['table_comments'] = $row['comments'];
		$i++;
		}
		
        echo json_encode($defined);
        
    }
	
    // 写入数据
    public function add() {
        $Defined = D("Defined");
        if ($vo = $Defined->create()) {
            $list = $Defined->add();
            if ($list !== false) {
                $this->success('数据保存成功！');
            } else {
                $this->error('数据写入错误！');
            }
        } else {
            $this->error($Defined->getError());
        }
    }

    // 更新数据
    public function edit() {
        $Defined = D("Defined");
        if ($vo = $Defined->create()) {
            $list = $Defined->save();
            if ($list !== false) {
                $this->success('数据更新成功！');
            } else {
                $this->error("没有更新任何数据!");
            }
        } else {
            $this->error($Defined->getError());
        }
    }

    // 删除数据
    public function remove() {
		$id = intval( $_POST['form_id'] );
        if (!empty($id)) {
            $Defined = M("Defined");
			$vo = $Defined->where("id='{$id}'")->find();
            if ($vo) {
				$Defined->where("pid='$id'")->delete();
				$result = $Defined->delete($id);
				if (false !== $result) {
					$this->success('删除成功！');
				} else {
					$this->error('删除出错！');
				}
			}
        } else {
            $this->error('ID错误！');
        }
    }

	 
	
	 

		
		
		
		
		
}
?>